<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-10-06 14:48:43
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: BOM成品工艺
 */

namespace App\Models;

use App\Traits\AutoCodeTrait;
use App\Traits\MaterialTrait;
use App\Traits\CarTrait;

class ProOutsourcingDelivery extends BaseModel
    {
    use MaterialTrait;
    use CarTrait;
    use AutoCodeTrait;

    public $ACSign = "PRO_OUT_DELIVERY";
    public $timestamps = true;
    public $table = "sys_pro_outsourcing_delivery";
    protected $guarded = [];

    public function process_route()
        {
        return $this->belongsTo(ProProcessRoute::class);
        }
    public function processes()
        {
        return $this->hasMany(ProOutsourcingDeliveryProcesses::class, "main_id");
        }
    public function details()
        {
        return $this->hasMany(ProOutsourcingDeliveryDetail::class, "code", 'code');
        }
    public function status()
        {
        return $this->belongsTo(Dic::class, "status_id", "key")->where(function ($q)
            {
            $q->where("code", 'status_with_finance');
            });
        }
    public function outfactory()
        {
        return $this->belongsTo(Company::class);
        }
    public function raws()
        {
        return $this->HasMany(ProOutsourcingDeliveryRaw::class, "main_id");
        }
    public function packs()
        {
        return $this->hasMany(ProOutsourcingDeliveryPack::class, "main_id");
        }
    /**
     * Summary of car
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @author sunkaiyuan
     */
    public function car()
        {
        return $this->belongsTo(ComprehensiveCar::class);
        }
    }
